<?php

	$errors = array();
	if($_SESSION['user'] && (unserialize($_SESSION['user'] instanceOf User)))
	{
		$this->setAction('admin/manage');
		return;
	}
	
	if($_POST['login'])
	{
		try
		{
			$user = UserMapper::get()->findByUsernameAndPassword($_POST['username'], $_POST['password']);
			$_SESSION['user'] = serialize($user);
			$this->setGuiMode('ajax');
			header('Location: /blog/admin/manage');
			return;
		}
		catch(FrameworkRecordNotFoundException $e)
		{
			$errors[] = "Couldn't find the username/password combination requested";
		}
	}
	$this->view()->assign('errors', $errors);
	$this->addInclude('app/css/areas/admin/login.css','css');
?>